package com.example.petplatform.controller;

import com.example.petplatform.common.Result;
import com.example.petplatform.entity.Param.Params;
import com.example.petplatform.entity.AdoptionApplication;
import com.example.petplatform.service.AdoptionApplicationService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 动物领养记录管理接口
 */
@RestController
@RequestMapping("/applications")
public class AdoptionApplicationController {
    @Resource
    private AdoptionApplicationService adoptionApplicationService;

    //获取所有领养申请记录
    @GetMapping("/getAllApplications")
    public Result getAllApplications() {
        List<AdoptionApplication> list = adoptionApplicationService.getAllApplications();
        return Result.success(list);
    }

    //分页查询领养申请记录
    @GetMapping("/applicationSearch")
    public Result applicationSearch(Params params) {
        PageInfo<AdoptionApplication> list = adoptionApplicationService.applicationSearch(params);
        return Result.success(list);
    }

    //添加或修改领养申请记录
    @PostMapping("/applicationAdd")
    public Result applicationAdd(@RequestBody AdoptionApplication application) {
        if(application.getId() == null) {
            // 添加数据
            List<AdoptionApplication> list = adoptionApplicationService.applicationAdd(application);
            return Result.success(list);
        } else {
            // 修改数据
            List<AdoptionApplication> list = adoptionApplicationService.applicationUpdate(application);
            return Result.success(list);
        }
    }

    //删除领养申请记录
    @DeleteMapping("/applicationDelete")
    public Result applicationDelete(@RequestBody AdoptionApplication application) {
        List<AdoptionApplication> list = adoptionApplicationService.applicationDelete(application.getId());
        return Result.success(list);
    }
}
